package io.adminboot.manager;

import io.adminboot.entity.User;
import io.adminboot.system.cache.AppTokenCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class TokenManager {

    @Autowired
    private AppTokenCache appTokenCache;

    public String generateToken(User user) {
        final String uuid = UUID.randomUUID().toString();
        appTokenCache.put(uuid, user);
        return uuid;
    }

    public User getUserByToken(String token) {
        return appTokenCache.get(token);
    }

}
